
function cToolButton()
{
	this.originalSrc = "";
	this.hoversrc = "";
	this.houtsrc = "";
}

function cToolButtonGroup()
{
	this.id = "";
	this.tools = new Array;
	this.buttons = new Array;
	
	this.PushButton = function(element)
	{
		var newbutton = new cToolButton();
		newbutton.originalSrc = element.originalSrc
		newbutton.hoversrc = element.hoversrc
		newbutton.houtsrc = element.houtsrc
		
		this.tools.push(newbutton);
		this.buttons.push(element);
	}
	
	this.GetIndex = function()
	{
		return (this.buttons.length-1);
	}
	
	this.GetLength = function()
	{
		return this.buttons.length;
	}
}

function cButtonGroups()
{
	this.groups = new Array;
	
	this.FindGroup = function(id)
	{
		var gLen = this.GetGroupLength();
		for(var i = 0; i < gLen ; i++)
		{
			if (this.groups[i].id == id)
			{
				return this.groups[i];
			}
		}
		return null;
	}
	
	this.GetGroupLength = function()
	{
		return this.groups.length;
	}
	
	this.PushGroup = function(id)
	{
		var group = new cToolButtonGroup();
		group.id 		= id;
		this.groups.push(group);
	}
	
	this.PushButton = function(toolBar)
	{
		var element = toolBar.element[0];
		
		var group = this.FindGroup(element.group);
		
		if(group == null){
			this.PushGroup(element.group);
			group = this.FindGroup(element.group);
		}
		group.PushButton(element);
		
		return group.GetIndex();
	}
	
	this.OnButtonClick = function(toolBar)
	{
		var element = toolBar.element[0];
		
		var group = this.FindGroup(element.group);
		var len = group.GetLength();
		
		for(var i = 0; i < len ; i++)
		{
			var originalSrc = group.tools[i].originalSrc;
			var hoversrc = group.tools[i].hoversrc;
			group.buttons[i].parent.setSrc(originalSrc , hoversrc);
		}
		var index = element.buttonIndex;
		var houtsrc = group.tools[index].houtsrc;
		element.parent.setSrc(houtsrc , houtsrc);
	}
	
	this.ButtonClear = function(groupID)
	{
		var group = this.FindGroup(groupID);
		var len = group.GetLength();
		for(var i = 0; i < len ; i++)
		{
			var originalSrc = group.tools[i].originalSrc;
			var hoversrc = group.tools[i].hoversrc;
			group.buttons[i].parent.setSrc(originalSrc , hoversrc);
		}
	}
	
	this.ButtonSelect = function(groupID , index)
	{
		var group = this.FindGroup(groupID);
		var len = group.GetLength();
		for(var i = 0; i < len ; i++)
		{
			var originalSrc = group.tools[i].originalSrc;
			var hoversrc = group.tools[i].hoversrc;
			group.buttons[i].parent.setSrc(originalSrc , hoversrc);
		}
		var houtsrc = group.tools[index].houtsrc;
		group.buttons[index].parent.setSrc(houtsrc , houtsrc);
	}
}

var _ToolBarGroup = new cButtonGroups();